// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-12-31

#ifndef __DBMSG_BASE_H_COMMON_SVR_BASE__
#define __DBMSG_BASE_H_COMMON_SVR_BASE__

#pragma once

#include <common/base/tinyxml.h>
#include "db_command.h"

namespace JoyServer
{

enum JoyDbMsgType
{
#   define JOY_DBMSG_DEF(type, id) DBMSG_##type = id,
#   include "dbmsg_msgdef.h"
};

class CJoyServer;

class CJoyDbMsg
{
public:
    int     m_type;
    CString m_content;
    CJoyXmlElement* m_root;

    CJoyDbMsg()
    {
        m_type = 0;
        m_root = NULL;
    }
    ~CJoyDbMsg()
    {
        if(m_root != NULL)
        {
            delete m_root;
        }
    }
};

class CJoyDbMsgHandler
{
public:
#   define JOY_DBMSG_DEF(name, id) virtual void OnDbMsg_##name(const CJoyDbMsg&) {}
#   include "dbmsg_msgdef.h"
public:
    CJoyServer* m_server;
public:
    CJoyDbMsgHandler();
    virtual ~CJoyDbMsgHandler();

    virtual void DbMsg_Recv(const CJoyDbMsg& msg);
    virtual void DbMsg_Rowset(CJoyDbCommand& row);

    virtual bool Create(CJoyServer* pServer);
    virtual void Destroy();

    void SendMsg(UINT serverId, UINT msgType, const CString& strContent);
    bool GetUserServer(UINT userId, UINT& loginServer, UINT& tempLoginId, UINT& mainServer, UINT& tempMainId);

    // blocking call, used for processing login message.
    virtual void KickUserLoginTemp(UINT userId, UINT err);
    virtual void KickUserMainTemp(UINT userId, UINT err, UINT mainServer, UINT tempMainId);

};

} // namespace JoyServer

#endif  // __DBMSG_BASE_H_COMMON_SVR_BASE__